package com.neusoft.hifly.information.article.entity;

import java.io.Serializable;
import java.time.LocalDateTime;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
import org.apache.commons.lang3.builder.ToStringBuilder;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;

import com.neusoft.hifly.commons.lang.LocalDateUtil;
import com.neusoft.hifly.commons.lang.StringConstants;
import com.neusoft.hifly.core.utils.GlobalConstants;
import com.neusoft.hifly.information.column.entity.ColumnObj;
import io.swagger.annotations.ApiModelProperty;

/**
 * Title: 文章资讯服务
 * <p>
 * Description: 文章对象
 * <p>
 * Copyright: 2019
 * <p>
 * Company: 东软汉枫
 *
 * @author lh_neu
 * @version 1.0.0
 */
@JsonIgnoreProperties(ignoreUnknown = true)
@TableName(value = GlobalConstants.DYNAMIC_TABLE_NAME_PREFIX + "_INFO_ARTICLE")
public class ArticleObj implements Serializable {
	private static final long serialVersionUID = -158218608309928L;

	/**
	 * 文章状态：编辑
	 */
	public static final String STATUS_0 = "0";

	/**
	 * 文章状态：校对
	 */
	public static final String STATUS_1 = "1";

	/**
	 * 文章状态：审核
	 */
	public static final String STATUS_2 = "2";

	/**
	 * 文章状态：发布
	 */
	public static final String STATUS_3 = "3";

	/**
	 * 是否允许评论：0否
	 */
	public static final String COMMENT_0 = "0";

	/**
	 * 是否允许评论：1评论/需要审核
	 */
	public static final String COMMENT_1 = "1";

	/**
	 * 是否允许评论：2评论/不需要审核
	 */
	public static final String COMMENT_2 = "2";

	// 主键
	@TableId(value = "ID")
	@ApiModelProperty(value = "主键")
	private long id;
	// 逻辑ID
	@TableField(value = "LOGIC_ID")
	@ApiModelProperty(value = "逻辑ID")
	private long logicId;
	// 租户逻辑ID
	@TableField(value = "ORGAN_LOGIC_ID")
	@ApiModelProperty(value = "租户逻辑ID")
	private long organLogicId;
	// 标题
	@TableField(value = "ARTICLE_TITLE")
	@ApiModelProperty(value = "标题")
	private String title;
	// 标题图片
	@TableField(value = "ARTICLE_IMG")
	@ApiModelProperty(value = "标题图片")
	private String img;
	// 副标题
	@TableField(value = "ARTICLE_SUBHEAD")
	@ApiModelProperty(value = "副标题")
	private String subhead;
	// 内容概述
	@TableField(value = "ARTICLE_SUMMARY")
	@ApiModelProperty(value = "内容概述")
	private String summary;
	// 关键字、文号
	@TableField(value = "ARTICLE_KEY")
	@ApiModelProperty(value = "关键字、文号")
	private String artKey;
	// 排序（降序）
	@TableField(value = "ARTICLE_ORDER")
	@ApiModelProperty(value = "排序（降序）")
	private int myOrder;
	// 是否发布(默认0否，1是)
	@TableField(value = "IS_PUB")
	@ApiModelProperty(value = "是否发布(默认0否，1是)", example = "0")
	private String isPub;
	// 文章状态(0起草,1编辑,2校对,3审核,4发布)
	@TableField(value = "ARTICLE_STATUS")
	@ApiModelProperty(value = "文章状态(0起草,1编辑,2校对,3审核,4发布)", example = "0")
	private String status;
	// 原出处
	@TableField(value = "ARTICLE_QORIGINAL")
	@ApiModelProperty(value = "原出处")
	private String qoriginal;
	// 文章浏览量
	@TableField(value = "PAGE_VIEWS")
	@ApiModelProperty(value = "文章浏览量")
	private int pageViews;
	// 文章点赞量
	@TableField(value = "PAGE_GOODS")
	@ApiModelProperty(value = "文章点赞量")
	private int pageGoods;
	// 作者
	@TableField(value = "ARTICLE_WRITER")
	@ApiModelProperty(value = "作者")
	private String writer;
	// 投稿人ID
	@TableField(value = "USER_ID")
	@ApiModelProperty(value = "投稿人ID")
	private long userId;
	// 投稿人姓名
	@TableField(value = "USER_NAME")
	@ApiModelProperty(value = "投稿人姓名")
	private String userName;
	// 投稿部门ID
	@TableField(value = "ORG_ID")
	@ApiModelProperty(value = "投稿部门ID")
	private long orgId;
	// 投稿部门名称
	@TableField(value = "ORG_NAME")
	@ApiModelProperty(value = "投稿部门名称")
	private String orgName;
	// 是否头条(默认0否，1是)
	@TableField(value = "IS_TOPLINE")
	@ApiModelProperty(value = "是否头条(默认0否，1是)", example = "0")
	private String isTopline;
	// 是否顶置(默认0否，1是)
	@TableField(value = "IS_STICK")
	@ApiModelProperty(value = "是否顶置(默认0否，1是)", example = "0")
	private String isStick;
	// 是否评论(默认0否，1是)
	@TableField(value = "IS_COMMENT")
	@ApiModelProperty(value = "是否评论(默认0否，1是)", example = "0")
	private String isComment;
	// 生效时间
	@TableField(value = "SEND_TIME")
	@ApiModelProperty(value = "生效时间")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonDeserialize(using = LocalDateTimeDeserializer.class)
	@JsonSerialize(using = LocalDateTimeSerializer.class)
	private LocalDateTime sendTime;
	// 失效时间
	@TableField(value = "END_TIME")
	@ApiModelProperty(value = "失效时间")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonDeserialize(using = LocalDateTimeDeserializer.class)
	@JsonSerialize(using = LocalDateTimeSerializer.class)
	private LocalDateTime endTime;
	// 发布时间
	@TableField(value = "PUB_TIME")
	@ApiModelProperty(value = "发布时间")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonDeserialize(using = LocalDateTimeDeserializer.class)
	@JsonSerialize(using = LocalDateTimeSerializer.class)
	private LocalDateTime pubTime;
	// 是否同步到微网站(默认0否，1是)
	@TableField(value = "SYNC_MINI_SITE")
	@ApiModelProperty(value = "是否同步到微网站(默认0否，1是)", example = "0")
	private String syncMiniSite;
	// 是否同步到手机(默认0否，1是)
	@TableField(value = "SYNC_APP")
	@ApiModelProperty(value = "是否同步到手机(默认0否，1是)", example = "0")
	private String syncApp;
	// 当前栏目ID（只存储一个栏目ID，创建文章时选的那个）
	@TableField(value = "COLUMN_LOGIC_ID")
	@ApiModelProperty(value = "当前栏目ID")
	private long columnLogicId;
	// 当前栏目名称（只存储一个栏目ID，创建文章时选的那个）
	@TableField(value = "COLUMN_NAME")
	@ApiModelProperty(value = "当前栏目名称")
	private String columnName;
	// 创建人
	@TableField(value = "CREATE_PERSON")
	@ApiModelProperty(value = "创建人")
	private String createPerson;
	// 创建人ID
	@TableField(value = "CREATE_PERSON_ID")
	@ApiModelProperty(value = "创建人ID")
	private long createPersonId;
	// 创建时间
	@TableField(value = "CREATE_TIME")
	@ApiModelProperty(value = "创建时间")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonDeserialize(using = LocalDateTimeDeserializer.class)
	@JsonSerialize(using = LocalDateTimeSerializer.class)
	private LocalDateTime createTime;
	// 修改人
	@TableField(value = "UPDATE_PERSON")
	@ApiModelProperty(value = "修改人")
	private String updatePerson;
	// 修改时间
	@TableField(value = "UPDATE_TIME")
	@ApiModelProperty(value = "修改时间")
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	@JsonDeserialize(using = LocalDateTimeDeserializer.class)
	@JsonSerialize(using = LocalDateTimeSerializer.class)
	private LocalDateTime updateTime;

	// ################### 临时数据 ####################

	// 格式化后的字符串日期
	@TableField(exist = false)
	private String createTimeStr;
	@TableField(exist = false)
	private String updateTimeStr;
	@TableField(exist = false)
	private String pubTimeStr;
	// 文章模板
	@TableField(exist = false)
	private String articleTemplate;
	// 租户
	@TableField(exist = false)
	private String organCode;
	// 文章内容
	@TableField(exist = false)
	private ArticleInfoObj info;
	// 文章扩展
	@TableField(exist = false)
	private ArticleExtObj ext;
	@TableField(exist = false)
	private String statusStr;
	@TableField(exist = false)
	private String statusString;

	/**
	 * 得到对象的哈希值
	 *
	 * @return int 对象的哈希值
	 */
	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(this.getLogicId()).toHashCode();
	}

	/**
	 * 比较两个对象是否相等
	 *
	 * @param other
	 *            要比较的对象
	 * @return boolean 相同返回true，否则返回flase
	 */
	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof ArticleObj)) {
			return false;
		}
		final ArticleObj castOther = (ArticleObj) other;
		return new EqualsBuilder().append(this.getLogicId(), castOther.getLogicId()).isEquals();
	}

	/**
	 * 返回对象的字符串值
	 *
	 * @return String 表示用户对象的字符串值
	 */
	@Override
	public String toString() {
		return new ToStringBuilder(this).append("文章", this.getTitle()).toString();
	}

	/**
	 * 文章状态
	 *
	 * @return 文章状态
	 */
	public String getStatusStr() {
		if (ArticleObj.STATUS_0.equals(this.status)) {
			this.statusStr = "编辑";
		} else if (ArticleObj.STATUS_1.equals(this.status)) {
			this.statusStr = "校对";
		} else if (ArticleObj.STATUS_2.equals(this.status)) {
			this.statusStr = "审核";
		} else if (ArticleObj.STATUS_3.equals(this.status)) {
			this.statusStr = "发布";
		}
		return statusStr;
	}

	/**
	 * 文章状态
	 *
	 * @return 文章状态
	 */
	public String getStatusString() {
		if (ArticleObj.STATUS_0.equals(this.status)) {
			this.statusString = "待编辑";
		} else if (ArticleObj.STATUS_1.equals(this.status)) {
			this.statusString = "待校对";
		} else if (ArticleObj.STATUS_2.equals(this.status)) {
			this.statusString = "待审核";
		} else if (ArticleObj.STATUS_3.equals(this.status)) {
			this.statusString = "已发布";
		}
		return statusString;
	}

	/**
	 * 将DATE类型的时间格式化为字符串类型
	 *
	 * @return 字符串时间
	 */
	public String getUpdateTimeStr() {
		if (this.updateTime != null) {
			this.updateTimeStr = LocalDateUtil.showTime(this.updateTime);
		}
		return this.updateTimeStr;
	}

	/**
	 * 将DATE类型的时间格式化为字符串类型
	 *
	 * @return 字符串时间
	 */
	public String getCreateTimeStr() {
		if (this.createTime != null) {
			this.createTimeStr = LocalDateUtil.showTime(this.createTime);
		}
		return this.createTimeStr;
	}

	/**
	 * 将DATE类型的时间格式化为字符串类型
	 *
	 * @return 字符串时间
	 */
	public String getPubTimeStr() {
		if (this.pubTime != null) {
			this.pubTimeStr = LocalDateUtil.showTime(this.pubTime);
		}
		return this.pubTimeStr;
	}

	/**
	 * 判断文章是否可以发布
	 * <p>
	 * 通过状态，生效/失效时间等属性判断
	 *
	 * @return 是否可以发布
	 */
	public boolean isCanRelease() {
		boolean isOk = false;

		// 首先通过状态判断是否可发布
		if (ArticleObj.STATUS_3.equalsIgnoreCase(this.status)) {
			isOk = true;
		} else {
			isOk = false;
		}

		// 通过生效/失效时间判断是否可发布
		if (sendTime != null) {
			if (isOk && LocalDateUtil.checkTime(LocalDateTime.now(), sendTime)) {
				isOk = true;
			} else {
				isOk = false;
			}
		}
		if (endTime != null) {
			if (isOk && LocalDateUtil.checkTime(endTime, LocalDateTime.now())) {
				isOk = true;
			} else {
				isOk = false;
			}
		}

		return isOk;
	}

	/**
	 * 是否发布
	 *
	 * @return 是否发布
	 */
	public String getIsPub() {
		if (StringUtils.isEmpty(isPub)) {
			this.isPub = StringConstants.NO;
		}
		return isPub;
	}

	/**
	 * 文章状态
	 *
	 * @return 文章状态
	 */
	public String getStatus() {
		if (StringUtils.isEmpty(status)) {
			this.status = StringConstants.NO;
		}
		return status;
	}

	/**
	 * 是否头条
	 *
	 * @return 是否头条
	 */
	public String getIsTopline() {
		if (StringUtils.isEmpty(isTopline)) {
			this.isTopline = StringConstants.NO;
		}
		return isTopline;
	}

	/**
	 * 是否顶置
	 *
	 * @return 是否顶置
	 */
	public String getIsStick() {
		if (StringUtils.isEmpty(isStick)) {
			this.isStick = StringConstants.NO;
		}
		return isStick;
	}

	/**
	 * 是否同步到微网站
	 *
	 * @return 是否同步到微网站
	 */
	public String getSyncMiniSite() {
		if (StringUtils.isEmpty(syncMiniSite)) {
			this.syncMiniSite = StringConstants.NO;
		}
		return syncMiniSite;
	}

	/**
	 * 是否同步到手机
	 *
	 * @return 是否同步到手机
	 */
	public String getSyncApp() {
		if (StringUtils.isEmpty(syncApp)) {
			this.syncApp = StringConstants.NO;
		}
		return syncApp;
	}

	/**
	 * 是否评论
	 *
	 * @return 是否评论
	 */
	public String getIsComment() {
		if (StringUtils.isEmpty(isComment)) {
			this.isComment = StringConstants.NO;
		}
		return isComment;
	}

	/**
	 * 默认模板
	 *
	 * @return 默认模板
	 */
	public String getArticleTemplate() {
		if (StringUtils.isEmpty(articleTemplate)) {
			this.articleTemplate = ColumnObj.TEMPLATE_DEF;
		}
		return articleTemplate;
	}

	public long getId() {
		return id;
	}

	public void setId(final long id) {
		this.id = id;
	}

	public long getLogicId() {
		return logicId;
	}

	public void setLogicId(final long logicId) {
		this.logicId = logicId;
	}

	public long getOrganLogicId() {
		return organLogicId;
	}

	public void setOrganLogicId(final long organLogicId) {
		this.organLogicId = organLogicId;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(final String title) {
		this.title = title;
	}

	public String getImg() {
		return img;
	}

	public void setImg(final String img) {
		this.img = img;
	}

	public String getSubhead() {
		return subhead;
	}

	public void setSubhead(final String subhead) {
		this.subhead = subhead;
	}

	public String getSummary() {
		return summary;
	}

	public void setSummary(final String summary) {
		this.summary = summary;
	}

	public String getArtKey() {
		return artKey;
	}

	public void setArtKey(final String artKey) {
		this.artKey = artKey;
	}

	public int getMyOrder() {
		return myOrder;
	}

	public void setMyOrder(final int myOrder) {
		this.myOrder = myOrder;
	}

	public String getQoriginal() {
		return qoriginal;
	}

	public void setQoriginal(final String qoriginal) {
		this.qoriginal = qoriginal;
	}

	public int getPageViews() {
		return pageViews;
	}

	public void setPageViews(final int pageViews) {
		this.pageViews = pageViews;
	}

	public int getPageGoods() {
		return pageGoods;
	}

	public void setPageGoods(final int pageGoods) {
		this.pageGoods = pageGoods;
	}

	public String getWriter() {
		return writer;
	}

	public void setWriter(final String writer) {
		this.writer = writer;
	}

	public long getUserId() {
		return userId;
	}

	public void setUserId(final long userId) {
		this.userId = userId;
	}

	public String getUserName() {
		return userName;
	}

	public void setUserName(final String userName) {
		this.userName = userName;
	}

	public long getOrgId() {
		return orgId;
	}

	public void setOrgId(final long orgId) {
		this.orgId = orgId;
	}

	public String getOrgName() {
		return orgName;
	}

	public void setOrgName(final String orgName) {
		this.orgName = orgName;
	}

	public LocalDateTime getSendTime() {
		return sendTime;
	}

	public void setSendTime(final LocalDateTime sendTime) {
		this.sendTime = sendTime;
	}

	public LocalDateTime getEndTime() {
		return endTime;
	}

	public void setEndTime(final LocalDateTime endTime) {
		this.endTime = endTime;
	}

	public LocalDateTime getPubTime() {
		return pubTime;
	}

	public void setPubTime(final LocalDateTime pubTime) {
		this.pubTime = pubTime;
	}

	public long getColumnLogicId() {
		return columnLogicId;
	}

	public void setColumnLogicId(final long columnLogicId) {
		this.columnLogicId = columnLogicId;
	}

	public String getColumnName() {
		return columnName;
	}

	public void setColumnName(final String columnName) {
		this.columnName = columnName;
	}

	public String getCreatePerson() {
		return createPerson;
	}

	public void setCreatePerson(final String createPerson) {
		this.createPerson = createPerson;
	}

	public long getCreatePersonId() {
		return createPersonId;
	}

	public void setCreatePersonId(final long createPersonId) {
		this.createPersonId = createPersonId;
	}

	public LocalDateTime getCreateTime() {
		return createTime;
	}

	public void setCreateTime(final LocalDateTime createTime) {
		this.createTime = createTime;
	}

	public String getUpdatePerson() {
		return updatePerson;
	}

	public void setUpdatePerson(final String updatePerson) {
		this.updatePerson = updatePerson;
	}

	public LocalDateTime getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(final LocalDateTime updateTime) {
		this.updateTime = updateTime;
	}

	public String getOrganCode() {
		return organCode;
	}

	public void setOrganCode(final String organCode) {
		this.organCode = organCode;
	}

	public ArticleInfoObj getInfo() {
		return info;
	}

	public void setInfo(final ArticleInfoObj info) {
		this.info = info;
	}

	public ArticleExtObj getExt() {
		return ext;
	}

	public void setExt(final ArticleExtObj ext) {
		this.ext = ext;
	}

	public void setIsPub(final String isPub) {
		this.isPub = isPub;
	}

	public void setStatus(final String status) {
		this.status = status;
	}

	public void setIsTopline(final String isTopline) {
		this.isTopline = isTopline;
	}

	public void setIsStick(final String isStick) {
		this.isStick = isStick;
	}

	public void setIsComment(final String isComment) {
		this.isComment = isComment;
	}

	public void setSyncMiniSite(final String syncMiniSite) {
		this.syncMiniSite = syncMiniSite;
	}

	public void setSyncApp(final String syncApp) {
		this.syncApp = syncApp;
	}

	public void setCreateTimeStr(final String createTimeStr) {
		this.createTimeStr = createTimeStr;
	}

	public void setUpdateTimeStr(final String updateTimeStr) {
		this.updateTimeStr = updateTimeStr;
	}

	public void setPubTimeStr(final String pubTimeStr) {
		this.pubTimeStr = pubTimeStr;
	}

	public void setArticleTemplate(final String articleTemplate) {
		this.articleTemplate = articleTemplate;
	}

	public void setStatusStr(final String statusStr) {
		this.statusStr = statusStr;
	}

	public void setStatusString(final String statusString) {
		this.statusString = statusString;
	}

}